/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.cpqd.ssar.utilitarias;

/**
 *
 * @author dvaranda
 */
public class Util {

    static public Float stringToFloat(String valor){
        Float aux;
        if (valor == null){
            aux = null;
        }else{
            valor = valor.replace(".", "").replace(",", ".");
            try {
                aux = Float.parseFloat(valor);
            } catch (NumberFormatException e) {
                aux = null;
            }
        }
        return aux;
    }

    static public Double decimalFormat(double valor, int decimais){
        return Math.round(valor * Math.pow(10, decimais)) / Math.pow(10, decimais);
    }

    static public Float decimalFormat(float valor, int decimais){
        return Math.round(valor * new Double(Math.pow(10, decimais)).floatValue()) / new Double(Math.pow(10, decimais)).floatValue();
    }

}
